﻿<?php
	session_start();

	if(isset($_SESSION['username']))
	{
		$username = $_SESSION['username'];
	}
	else
	{
		$key = $_GET['key'];
		if(isset($key))
		{
			include 'config.php';
			mysqli_set_charset($con, 'utf8');
			$sql = "SELECT Login FROM User WHERE ResetKey = '$key'";
			
			$result = mysqli_query($con,$sql);
			$count=mysqli_num_rows($result);
			if($count == 1)
			{
				$row = mysqli_fetch_array($result);
				
				$username = $row['Login'];
			}
		}
		else
		{
			$_SESSION['message'] = "Something went wrong.";
			header ("Location: index.php");
		}
		
		
	}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<title>Sales Makeover</title>
</head>

<body>
	<div class="bodyLeft" id="bodyLeft">
		<?php if (isset($_SESSION['login']) && $_SESSION['login'] == true) { include("menu.html"); } ?>
	</div>
	<div class="bodyRight" id="bodyRight">
		<div class="container_head">
			<?php if (isset($_SESSION['login']) && $_SESSION['login'] == true) { include("header.html"); } ?>
		</div>
		<div class="container">
			<div class="form_container">
				<p class="containerText">Skriv in ditt nya lösenord.</p>
				<?php 
					if(isset($_GET['key']))
					{
						$key = $_GET['key'];
						echo "<form id=\"form_login\" class=\"form_login\" method=\"post\" action=\"reseting.php?key=" . $key . "\" accept-charset=\"UTF-8\">";
					}
					else
					{
						echo "<form id=\"form_login\" class=\"form_login\" method=\"post\" action=\"reseting.php\" accept-charset=\"UTF-8\">";
					}
					echo "<input style='margin-left: auto; margin-right:auto;' type=\"email\" name=\"login\" onfocus=\"if(this.value == '" . $username . "') { this.value = ''; }\" onblur=\"if(this.value == '') { this.value = '" . $username . "'; }\" value=\"" . $username . "\">";
					
					if(isset($key))
						echo "<input style='margin-left: auto; margin-right:auto;' type=\"password\" name=\"password\" onfocus=\"if(this.value == 'Lösenord') { this.value = ''; }\" onblur=\"if(this.value == '') { this.value = 'Lösenord'; }\" value=\"Lösenord\">";
					
						
					echo "<input style='margin-left: auto; margin-right:auto;margin-top: 50px;' type=\"submit\" value=\"Skicka\">";
					echo "</form>";
						
				?>
					
			</div>
		</div>
	</div>
</body>

</html>